#! /bin/sh

# LAS file location and name
las=./las/well_logs.las

# curve order in las file (p-sonic, s-sonic, density)
pson=2
sson=3
den=4

# bacus averaging window length (in depth samples)
# (note depth is in meters after las2su)
navg=201


# output window geometry
WIDTH=300
HEIGHT=400
WIDTHOFF1=0
WIDTHOFF2=315
WIDTHOFF3=630
WIDTHOFF4=945
HEIGHTOFF1=30
HEIGHTOFF2=480
HEIGHTOFF3=930

# read log file convert depth to meters
las2su < $las m=1 > logs.su

# pull off depth track 
suwind < logs.su min=1 max=1 > depth.su

# pull off p-sonic and convert to velocity (m/s) 
suwind < logs.su min=$pson max=$pson | suop op=s2vm > vp.su

# pull off s-sonic and convert to velocity (m/s) 
suwind < logs.su min=$sson max=$sson | suop op=s2vm > vs.su

# pull off density (g/cc) and convert to metric (kg/m^3) 
suwind < logs.su min=$den max=$den | suop op=d2m > rho.su

# put needed logs together in needed order
cat vp.su vs.su rho.su > vp_vs_rho.su

# do backus averaging
subackus < vp_vs_rho.su navg=$navg all=1  > all.su

# pull off epsilon 
suwind < all.su min=1 max=1 > eps.su

# pull off delta 

suwind < all.su min=2 max=2 > delta.su
# pull off gamma 
suwind < all.su min=3 max=3 > gamma.su

# pull off vp0
suwind < all.su min=4 max=4 > vp0.su

# pull off vs0
suwind < all.su min=5 max=5 > vs0.su

# pull off backus-averaged density
suwind < all.su min=6 max=6 > rho_bac.su

# plot it up
suxgraph < vp.su title="Vp from logs"  label1=Meters label2=m/s \
  -geometry ${WIDTH}x${HEIGHT}+${WIDTHOFF1}+${HEIGHTOFF1} &
suxgraph < vs.su title="Vs from logs"  label1=Meters label2=m/s \
  -geometry ${WIDTH}x${HEIGHT}+${WIDTHOFF2}+${HEIGHTOFF1} &
suxgraph < rho.su title="Density from logs"  \
  label1=Meters label2=kg/m3 \
  -geometry ${WIDTH}x${HEIGHT}+${WIDTHOFF3}+${HEIGHTOFF1} &
suxgraph < vp0.su title="Backus Vp0"  label1=Meters label2=m/s \
  -geometry ${WIDTH}x${HEIGHT}+${WIDTHOFF1}+${HEIGHTOFF2} &
suxgraph < vs0.su title="Backus Vs0"  label1=Meters label2=m/s \
  -geometry ${WIDTH}x${HEIGHT}+${WIDTHOFF2}+${HEIGHTOFF2} &
suxgraph < rho_bac.su title="Backus density"  \
  label1=Meters label2=kg/m3 \
  -geometry ${WIDTH}x${HEIGHT}+${WIDTHOFF3}+${HEIGHTOFF2} &
suxgraph < eps.su title="Backus epsilon"  label1=Meters \
  -geometry ${WIDTH}x${HEIGHT}+${WIDTHOFF1}+${HEIGHTOFF3} &
suxgraph < delta.su title="Backus delta"  label1=Meters \
  -geometry ${WIDTH}x${HEIGHT}+${WIDTHOFF2}+${HEIGHTOFF3} &
suxgraph < gamma.su title="Backus gamma"  \
  label1=Meters \
  -geometry ${WIDTH}x${HEIGHT}+${WIDTHOFF3}+${HEIGHTOFF3} &

exit 0
